home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 701-725 / 708 / intuisup / intuisup42.lha / Intuisup / source.lha / Pointer / pointer.c < prev    next >
C/C++ Source or Header  |  1992-04-14  |  6KB  |  228 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1992 by Torsten Jürgeleit
  4.  *
  5.  *    Name .....: pointer.c
  6.  *    Created ..: Wednesday 08-Jan-92 22:34:41
  7.  *    Revision .: 1
  8.  *
  9.  *    Date        Author                 Comment
  10.  *    =========   ====================   ====================
  11.  *    13-Apr-92   Torsten Jürgeleit      remove menu for busy pointer
  12.  *    08-Jan-92   Torsten Jürgeleit      Created this file!
  13.  *
  14.  ****************************************************************************
  15.  *
  16.  *    Support routines for mouse pointer
  17.  *
  18.  * $Revision Header ********************************************************/
  19.  
  20.     /* Includes */
  21.  
  22. #include <exec/types.h>
  23. #include <exec/memory.h>
  24. #include <devices/input.h>
  25. #include <devices/inputevent.h>
  26. #include <intuition/intuition.h>
  27. #include <intuition/screens.h>
  28. #ifdef AZTEC_C
  29. #include <functions.h>   /* needed for Aztec C - prototypes and pragmas for all Amiga system functions */
  30. #endif
  31. #include <libraries/memwatch.h>   /* header file for memory debug link library (Fish 240) - AFTER functions.h */
  32. #include "/render/render.h"
  33. #include "pointer.h"
  34.  
  35.     /* Defines for for workbench busy ballon */
  36.  
  37. #define BUSY_POINTER_WIDTH    15
  38. #define BUSY_POINTER_HEIGHT    22
  39. #define BUSY_POINTER_XOFFSET    -7
  40. #define BUSY_POINTER_YOFFSET    -8
  41.  
  42.     /* Statics for for workbench busy ballon */
  43.  
  44. STATIC UWORD busy_pointer_image[] = {
  45.     0x0000, 0x0000,
  46.  
  47.     0x0600, 0x0600,
  48.     0x0f40, 0x0f40,
  49.     0x3fe0, 0x3fe0,
  50.     0x7fe0, 0x7fe0,
  51.     0x61f0, 0x7ff0,
  52.     0x7bf8, 0x7ff8,
  53.     0xf7f8, 0xfff8,
  54.     0x61fc, 0x7ffc,
  55.     0x7f0c, 0x7ffc,
  56.     0x3fde, 0x3ffe,
  57.     0x7fbc, 0x7ffc,
  58.     0x3f0c, 0x3ffc,
  59.     0x1ff8, 0x1ff8,
  60.     0x07f0, 0x07f0,
  61.     0x01c0, 0x01c0,
  62.     0x0700, 0x0700,
  63.     0x0fc0, 0x0fc0,
  64.     0x0680, 0x0680,
  65.     0x0000, 0x0000,
  66.     0x00c0, 0x00c0,
  67.     0x00e0, 0x00e0,
  68.     0x0040, 0x0040,
  69.  
  70.     0x0000, 0x0000
  71. };
  72. STATIC struct PointerData  busy_pointer_data = {
  73.     BUSY_POINTER_WIDTH,
  74.     BUSY_POINTER_HEIGHT,
  75.     BUSY_POINTER_XOFFSET,
  76.     BUSY_POINTER_YOFFSET,
  77.     &busy_pointer_image[0]
  78. };
  79.     /* Change mouse pointer for given window - save old one in singly linked list */
  80.  
  81.    VOID
  82. change_mouse_pointer(struct Window  *win, struct PointerData  *pd)
  83. {
  84.    if (win) {
  85.       struct PointerList  *pl;
  86.  
  87.       if (pl = AllocMem((LONG)sizeof(struct PointerList),
  88.                       (LONG)MEMF_PUBLIC | MEMF_CLEAR)) {
  89.      struct Menu  *menu = NULL;
  90.  
  91.      /* If no pointer data given then use busy pointer */
  92.      if (!pd) {
  93.         pd = &busy_pointer_data;
  94.  
  95.         /* Remove menu for busy pointer */
  96.         if (menu = win->MenuStrip) {
  97.            ClearMenuStrip(win);
  98.         }
  99.      }
  100.  
  101.      /* Allocate chipmem buffer for pointer data if necessary */
  102.      if (!(TypeOfMem((BYTE *)pd->pd_Data) & MEMF_CHIP) &&
  103.          !(pl->pl_Buffer = AllocMem(pl->pl_BufferSize = (pd->pd_Height +
  104.                   2) * 4, (LONG)MEMF_PUBLIC | MEMF_CHIP))) {
  105.         FreeMem(pl, (LONG)sizeof(struct PointerList));
  106.      } else {
  107.         UWORD *data;
  108.  
  109.         /* Init pointer list */
  110.         pl->pl_ID   = ISUP_ID;
  111.         pl->pl_Menu = menu;
  112.         if (!pl->pl_Buffer) {
  113.            data = pd->pd_Data;
  114.         } else {
  115.            data = pl->pl_Buffer;
  116.            CopyMem((BYTE *)pd->pd_Data, (BYTE *)data, pl->pl_BufferSize);
  117.         }
  118.  
  119.         /* Save old pointer data in pointer list */
  120.         Forbid();
  121.         pl->pl_Width   = win->PtrWidth;
  122.         pl->pl_Height  = win->PtrHeight;
  123.         pl->pl_XOffset = win->XOffset;
  124.         pl->pl_YOffset = win->YOffset;
  125.         pl->pl_Data    = win->Pointer;
  126.  
  127.         /* Append old window user data ptr and set new one */
  128.         pl->pl_Next   = (struct PointerList *)win->UserData;
  129.         win->UserData = (BYTE *)pl;
  130.         Permit();
  131.  
  132.         /* Install new pointer image */
  133.         SetPointer(win, data, (LONG)pd->pd_Height, (LONG)pd->pd_Width,
  134.                 (LONG)pd->pd_XOffset, (LONG)pd->pd_YOffset);
  135.      }
  136.       }
  137.    }
  138. }
  139.     /* Restore saved mouse pointer for given window - use first entry from singly linked list */
  140.  
  141.    VOID
  142. restore_mouse_pointer(struct Window  *win)
  143. {
  144.    if (win) {
  145.       struct PointerList  *pl;
  146.  
  147.       /* Get saved pointer - if no data given then use default one */
  148.       if ((pl = (struct PointerList *)win->UserData) &&
  149.                              pl->pl_ID == ISUP_ID) {
  150.      struct Menu  *menu;
  151.  
  152.      /* Remove first pointer from list */
  153.      win->UserData = (BYTE *)pl->pl_Next;
  154.  
  155.      /* Restore menu - if any */
  156.      if (menu = pl->pl_Menu) {
  157.         SetMenuStrip(win, menu);
  158.      }
  159.  
  160.      /* Restore pointer image and free pointer data */
  161.      SetPointer(win, pl->pl_Data, (LONG)pl->pl_Height,
  162.         (LONG)pl->pl_Width, (LONG)pl->pl_XOffset, (LONG)pl->pl_YOffset);
  163.      if (pl->pl_Buffer) {
  164.         FreeMem(pl->pl_Buffer, pl->pl_BufferSize);
  165.      }
  166.      FreeMem(pl, (LONG)sizeof(struct PointerList));
  167.       } else {
  168.      ClearPointer(win);
  169.       }
  170.    }
  171. }
  172.     /* Move mouse pointer to given position relativ to specified window */
  173.  
  174.    VOID
  175. move_mouse_pointer(struct Window  *win, SHORT x, SHORT y, BOOL button)
  176. {
  177.    struct MsgPort     *port;
  178.    struct IOStdReq    *ior;
  179.    struct InputEvent  *ie;
  180.  
  181.    if (win && (port = CreatePort((BYTE *)NULL, 0L))) {
  182.       if (ior = CreateStdIO(port)) {
  183.      if (!OpenDevice("input.device", 0L, (struct IORequest *)ior, 0L)) {
  184.         if (ie = AllocMem((LONG)sizeof(struct InputEvent),
  185.                       (LONG)MEMF_PUBLIC | MEMF_CLEAR)) {
  186.            struct Screen  *screen = win->WScreen;
  187.  
  188.            /* Init IO request */
  189.            ior->io_Command = IND_WRITEEVENT;
  190.            ior->io_Flags   = 0;
  191.            ior->io_Data    = (APTR)ie;
  192.            ior->io_Length  = sizeof(struct InputEvent);
  193.  
  194.            /* Convert mouse position */
  195.            x += win->LeftEdge;
  196.            y += win->TopEdge;
  197.            if (!(screen->ViewPort.Modes & HIRES)) {
  198.           x *= 2;
  199.            }
  200.            if (!(screen->ViewPort.Modes & LACE)) {
  201.           y *= 2;
  202.            }
  203.            y += 2 * screen->TopEdge;
  204.  
  205.            /* Init input event */
  206.            ie->ie_Class = IECLASS_POINTERPOS;
  207.            ie->ie_X     = x;
  208.            ie->ie_Y     = y;
  209.  
  210.            /* Send IO request - if button then first button down and then up event */
  211.            if (button) {
  212.           ie->ie_Code = IECODE_LBUTTON;
  213.           DoIO((struct IORequest *)ior);
  214.           ie->ie_Code = IECODE_LBUTTON | IECODE_UP_PREFIX;
  215.            } else {
  216.           ie->ie_Code = IECODE_NOBUTTON;
  217.            }
  218.            DoIO((struct IORequest *)ior);
  219.            FreeMem(ie, (LONG)sizeof(struct InputEvent));
  220.         }
  221.         CloseDevice((struct IORequest *)ior);
  222.      }
  223.      DeleteStdIO(ior);
  224.       }
  225.       DeletePort(port);
  226.    }
  227. }
  228.